package com.fgs.common.other;

/**
*@author fgs
*@date 2020/3/27
**/
public class CommonEvent {
    private int mWhat;
    private String mMessage;
    private String mMessageSource;

    public CommonEvent(int what) {
        this(what, null, null);
    }

    public CommonEvent(int what, String message) {
        this(what, message, null);
    }

    public CommonEvent(int what, String message, String messageSource) {
        this.mWhat = what;
        this.mMessage = message;
        this.mMessageSource = messageSource;
        if (this.mMessage == null) {
            this.mMessage = "";
        }

        if (this.mMessageSource == null) {
            this.mMessageSource = this.getClass().getSimpleName();
        }

    }

    public String getMessage() {
        return this.mMessage;
    }

    public void setMessage(String message) {
        this.mMessage = message;
    }

    public String getMessageSource() {
        return this.mMessageSource;
    }

    public void setMessageSource(String messageSource) {
        this.mMessageSource = messageSource;
    }

    public int getWhat() {
        return this.mWhat;
    }

    public void setWhat(int what) {
        this.mWhat = what;
    }

    public boolean isFrom(String messageSource) {
        return this.mMessageSource.equals(messageSource);
    }

    public boolean isFrom(Object object) {
        return this.isFrom(object.getClass().getSimpleName());
    }

    public static class Builder {
        private int mWhat;
        private String mMessage;
        private String mMessageSource;

        public Builder(int what) {
            this.mWhat = what;
        }

        public CommonEvent build() {
            return new CommonEvent(this.mWhat, this.mMessage, this.mMessageSource);
        }

        public CommonEvent.Builder setMessage(String message) {
            this.mMessage = message;
            return this;
        }

        public CommonEvent.Builder setMessageSource(String messageSource) {
            this.mMessageSource = messageSource;
            return this;
        }

        public CommonEvent.Builder setMessageSource(Object object) {
            return this.setMessageSource(object.getClass().getSimpleName());
        }
    }
}
